package com.bilibili.juc.aqs;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zuife
 * @description
 * @since 2024-05-16 10:01:44
 */
public class AQSDemo {
    public static void main(String[] args) {
        Lock lock = new ReentrantLock(false);//非公平锁
        new Thread(()->{
            lock.lock();
            try {
                System.out.println("------come in A");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }finally {
                lock.unlock();
            }
        },"A").start();
        //B是第二个顾客
        new Thread(()->{
            lock.lock();
            try {
                System.out.println("------come in B");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }finally {
                lock.unlock();
            }
        },"B").start();

    }
}
